home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 175 (1991-09-10)(Manewaldt, A.)(DE)(PD).zip / Taifun 175 (1991-09-10)(Manewaldt, A.)(DE)(PD).adf / Term / Source.LZH / Scale.c < prev    next >
C/C++ Source or Header  |  1991-07-06  |  6KB  |  269 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: Scale.c
  6.  *    Created ..: Monday 21-Jan-91 20:12
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    21-Jan-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17.     /* Some static data required by the bitmap scaling routine. */
  18.  
  19. STATIC struct RastPort        *ScaleRPort;
  20. STATIC struct BitMap        *ScaleSrcBitMap,*ScaleDstBitMap;
  21. STATIC struct BitScaleArgs    *ScaleArgs;
  22.  
  23. STATIC UBYTE             ScaleFontType = FONT_TOPAZ;
  24.  
  25.     /* DeleteScale():
  26.      *
  27.      *    Frees all the data associated with font scaling.
  28.      */
  29.  
  30. VOID
  31. DeleteScale()
  32. {
  33.     if(ScaleArgs)
  34.         FreeMem(ScaleArgs,sizeof(struct BitScaleArgs));
  35.  
  36.     ScaleArgs = NULL;
  37.  
  38.     if(ScaleDstBitMap)
  39.     {
  40.         if(ScaleDstBitMap -> Planes[0])
  41.             FreeMem(ScaleDstBitMap -> Planes[0],2 * 16 * ScaleDstBitMap -> Depth);
  42.  
  43.         FreeMem(ScaleDstBitMap,sizeof(struct BitMap));
  44.     }
  45.  
  46.     ScaleDstBitMap = NULL;
  47.  
  48.     if(ScaleSrcBitMap)
  49.     {
  50.         if(ScaleSrcBitMap -> Planes[0])
  51.             FreeMem(ScaleSrcBitMap -> Planes[0],2 * 8 * ScaleSrcBitMap -> Depth);
  52.  
  53.         FreeMem(ScaleSrcBitMap,sizeof(struct BitMap));
  54.     }
  55.  
  56.     ScaleSrcBitMap = NULL;
  57.  
  58.     if(ScaleRPort)
  59.         FreeMem(ScaleRPort,sizeof(struct RastPort));
  60.  
  61.     ScaleRPort = NULL;
  62. }
  63.  
  64.     /* CreateScale():
  65.      *
  66.      *    Sets up the data required for real-time font scaling
  67.      *    (bitmaps, rastports, etc.).
  68.      */
  69.  
  70. BYTE
  71. CreateScale()
  72. {
  73.     SHORT i;
  74.  
  75.     if(ScaleRPort = (struct RastPort *)AllocMem(sizeof(struct RastPort),MEMF_PUBLIC|MEMF_CLEAR))
  76.     {
  77.         InitRastPort(ScaleRPort);
  78.  
  79.         if(ScaleSrcBitMap = (struct BitMap *)AllocMem(sizeof(struct BitMap),MEMF_PUBLIC|MEMF_CLEAR))
  80.         {
  81.             InitBitMap(ScaleSrcBitMap,Screen -> RastPort . BitMap -> Depth,16,8);
  82.  
  83.             if(ScaleDstBitMap = (struct BitMap *)AllocMem(sizeof(struct BitMap),MEMF_PUBLIC|MEMF_CLEAR))
  84.             {
  85.                 InitBitMap(ScaleDstBitMap,Screen -> RastPort . BitMap -> Depth,16,16);
  86.  
  87.                 ScaleRPort -> BitMap = ScaleSrcBitMap;
  88.  
  89.                 if(ScaleSrcBitMap -> Planes[0] = (PLANEPTR)AllocMem(2 * 8 * ScaleSrcBitMap -> Depth,MEMF_CHIP|MEMF_CLEAR))
  90.                 {
  91.                     for(i = 1 ; i < ScaleSrcBitMap -> Depth ; i++)
  92.                         ScaleSrcBitMap -> Planes[i] = ScaleSrcBitMap -> Planes[0] + i * 2 * 8;
  93.  
  94.                     if(ScaleDstBitMap -> Planes[0] = (PLANEPTR)AllocMem(2 * 16 * ScaleDstBitMap -> Depth,MEMF_CHIP|MEMF_CLEAR))
  95.                     {
  96.                         for(i = 1 ; i < ScaleDstBitMap -> Depth ; i++)
  97.                             ScaleDstBitMap -> Planes[i] = ScaleDstBitMap -> Planes[0] + i * 2 * 16;
  98.  
  99.                         if(Config . Font == FONT_IBM && IBM)
  100.                             SetFont(ScaleRPort,IBM);
  101.                         else
  102.                             SetFont(ScaleRPort,Topaz);
  103.  
  104.                         ScaleFontType = Config . Font;
  105.  
  106.                         SetDrMd(ScaleRPort,JAM2);
  107.                         SetAPen(ScaleRPort,1);
  108.                         SetBPen(ScaleRPort,0);
  109.  
  110.                         if(ScaleArgs = (struct BitScaleArgs *)AllocMem(sizeof(struct BitScaleArgs),MEMF_PUBLIC|MEMF_CLEAR))
  111.                         {
  112.                             ScaleArgs -> bsa_SrcWidth    = 8;
  113.                             ScaleArgs -> bsa_SrcHeight    = 8;
  114.  
  115.                             ScaleArgs -> bsa_XSrcFactor    = 1;
  116.                             ScaleArgs -> bsa_YSrcFactor    = 1;
  117.  
  118.                             ScaleArgs -> bsa_XDestFactor    = 2;
  119.  
  120.                             ScaleArgs -> bsa_SrcBitMap    = ScaleSrcBitMap;
  121.                             ScaleArgs -> bsa_DestBitMap    = ScaleDstBitMap;
  122.  
  123.                             return(TRUE);
  124.                         }
  125.                     }
  126.                 }
  127.             }
  128.         }
  129.     }
  130.  
  131.     return(FALSE);
  132. }
  133.  
  134.     /* PrintScaled(UBYTE Char):
  135.      *
  136.      *    This is the big one: since VT100 supports a number of
  137.      *    font sizes (double height, double width, 132 columns),
  138.      *    the approriate characters are scaled in real-time before
  139.      *    they are displayed.
  140.      */
  141.  
  142. VOID
  143. PrintScaled(UBYTE Char)
  144. {
  145.     STATIC UBYTE LocalFgPen = 1,LocalBgPen = 0;
  146.  
  147.         /* Look for the font type to scale. */
  148.  
  149.     if(Config . Font != ScaleFontType)
  150.     {
  151.         if(Config . Font == FONT_IBM && IBM)
  152.             SetFont(ScaleRPort,IBM);
  153.         else
  154.             SetFont(ScaleRPort,Topaz);
  155.  
  156.         ScaleFontType = Config . Font;
  157.     }
  158.  
  159.         /* Set the approriate colours. */
  160.  
  161.     if(ScaleRPort -> FgPen != LocalFgPen)
  162.     {
  163.         SetAPen(ScaleRPort,FgPen);
  164.  
  165.         LocalFgPen = FgPen;
  166.     }
  167.  
  168.     if(ScaleRPort -> BgPen != LocalBgPen)
  169.     {
  170.         LocalBgPen = BgPen;
  171.  
  172.         SetBPen(ScaleRPort,BgPen);
  173.     }
  174.  
  175.         /* Print the character to be scaled into the
  176.          * invisible drawing area.
  177.          */
  178.  
  179.     Move(ScaleRPort,0,6);
  180.  
  181.     Text(ScaleRPort,&Char,1);
  182.  
  183.         /* Determine the scale of the destination character. */
  184.  
  185.     switch(Config . FontScale)
  186.     {
  187.             /* Twice as wide as the source data. */
  188.  
  189.         case SCALE_2X:    ScaleArgs -> bsa_YDestFactor = 1;
  190.  
  191.                 break;
  192.  
  193.             /* Half as wide as the source data. */
  194.  
  195.         case SCALE_HALF:ScaleArgs -> bsa_YDestFactor = 1;
  196.                 ScaleArgs -> bsa_XDestFactor = 1;
  197.  
  198.                 ScaleArgs -> bsa_XSrcFactor = 2;
  199.  
  200.                 break;
  201.  
  202.             /* Twice as high as the source data. */
  203.  
  204.         default:    ScaleArgs -> bsa_YDestFactor = 2;
  205.  
  206.                 break;
  207.     }
  208.  
  209.         /* Scale the font. */
  210.  
  211.     BitMapScale(ScaleArgs);
  212.  
  213.         /* Render the character. */
  214.  
  215.     switch(Config . FontScale)
  216.     {
  217.         case SCALE_TOP2X:    BltBitMapRastPort(ScaleDstBitMap,0,0,RPort,CursorX * 8,CursorY * 8,16,8,0xC0);
  218.  
  219.                     RasterPutString(&Char,1);
  220.  
  221.                     CursorX++;
  222.  
  223.                     RasterPutString(&Char,1);
  224.  
  225.                     CursorX++;
  226.  
  227.                     break;
  228.  
  229.         case SCALE_BOT2X:    BltBitMapRastPort(ScaleDstBitMap,0,8,RPort,CursorX * 8,CursorY * 8,16,8,0xC0);
  230.  
  231.                     RasterPutString(&Char,1);
  232.  
  233.                     CursorX++;
  234.  
  235.                     RasterPutString(&Char,1);
  236.  
  237.                     CursorX++;
  238.  
  239.                     break;
  240.  
  241.         case SCALE_2X:        BltBitMapRastPort(ScaleDstBitMap,0,0,RPort,CursorX * 8,CursorY * 8,16,8,0xC0);
  242.  
  243.                     RasterPutString(&Char,1);
  244.  
  245.                     CursorX++;
  246.  
  247.                     RasterPutString(" ",1);
  248.  
  249.                     CursorX++;
  250.  
  251.                     break;
  252.  
  253.         case SCALE_HALF:    BltBitMapRastPort(ScaleDstBitMap,0,0,RPort,CursorX * 4,CursorY * 8,4,8,0xC0);
  254.  
  255.                     RasterPutString(&Char,1);
  256.  
  257.                     CursorX++;
  258.  
  259.                     ScaleArgs -> bsa_XDestFactor    = 2;
  260.                     ScaleArgs -> bsa_XSrcFactor    = 1;
  261.  
  262.                     break;
  263.     }
  264.  
  265.         /* And set the new cursor position. */
  266.  
  267.     SetCursor();
  268. }
  269.